﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Text;
using SdmxMl.Structure;
using SdmxMl.Common;

namespace SdmxMl.Msg
{
    /// <summary>
    /// PartyType defines the information which is sent about various parties such
    /// as senders and receivers of messages. The Name is the ID of the party, and
    /// Contact provides contact details.
    /// </summary>
    public class PartyType
    {
        public PartyType()
        {
            _contact = new ContactTypeList();
            _name = new MultiLang();
        }

        public PartyType(string id, MultiLang name, ContactTypeList contact)
        {
            _id = id;
            _name = name;
            _contact = contact;
        }


        public void WriteXml(XmlTextWriter xw, string prefix, string tag)
        {
            string nMprefix = SdmxNamespaceManager.SdmxTarget == SdmxVersion.SDMX_21 ?
                "common" : null;

            if (_name.IsEmpty == false)
            {
                xw.WriteStartElement(prefix, tag, null);
                xw.WriteAttributeString("id", _id);
                _name.WriteXml(xw, nMprefix, "Name");
                foreach (ContactType ct in _contact)
                    ct.WriteXml(xw, prefix, "Contact");
                xw.WriteEndElement();
            }

        }

        //--------------------------------------------------------------------
        #region Properties
        private string _id;

        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }

        protected MultiLang _name;
        public MultiLang Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private ContactTypeList _contact;

        public ContactTypeList Contact
        {
            get { return _contact; }
            set { _contact = value; }
        }
        #endregion // Properties
    }
}
